package com.example.runner;

import com.example.dao.mysql.AccountMysqlDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/12/17 10:35
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
@Component // @Service 也行，@Service是引用了@Component，是对 @Component 扩展
public class PostConstructService {


    @Autowired
    private Environment environment;
    @Autowired
    private AccountMysqlDao accountMysqlDao;


    public void aa(){
        System.out.println("aaaaa");
    }

    /**
     *  多个 PostConstruct 执行顺序不确定 但是比 afterPropertiesSet 提前 CommandLineRunner 最后
     */

    @PostConstruct
    public void test1(){
        String property = environment.getProperty("aaa.bbb");
        System.out.println("11111111111111111111  PostConstruct 111"+accountMysqlDao);
    }

    @PostConstruct
    public void test2() throws InterruptedException {
        String property = environment.getProperty("aaa.bbb");
        System.out.println("22222222222222222222  PostConstruct 222"+accountMysqlDao);

        Thread.sleep(10000);

    }



    // 直接启动 tomcat 再关闭 并不会 触发，要用测试类
    @PreDestroy
    public void destory() {

        System.out.println("【【【【【【【【【【【  destory ");
    }

}
